package com.santiao.youxiang.ui.activity

import android.app.AlertDialog
import android.content.Context
import android.content.Intent
import android.os.Bundle
import android.util.Log
import android.view.View
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import com.gyf.immersionbar.ImmersionBar
//import com.lazyliuzy.commonui.ui.activity.Task3Activity

//import com.lazyliuzy.commonui.databinding.ActivityTask1Binding
//import com.lazyliuzy.commonui.utils.lzy.LZYADSUtils
import kotlin.apply
//import kotlin.jvm.java
import com.santiao.youxiang.R
import com.santiao.youxiang.databinding.ActivityComputeBinding

import com.santiao.youxiang.ext.thrillClickListener

class ComputeInsuranceActivity: AppCompatActivity() {
    private lateinit var binding: ActivityComputeBinding
//    private lateinit var lzyadsUtils: com.lazyliuzy.commonui.utils.lzy.LZYADSUtils
var type_a=""
    var struri=""
    // 在类顶部定义
    val REQUEST_STORAGE_PERMISSION = 1001  // 可以是任意唯一整数

    companion object {
        // 定义一个静态方法来创建Intent
        // 定义一个静态方法来创建Intent并携带uri数据
        fun startActivity(context: Context?, type: String) {

            val intent = Intent(context, ComputeInsuranceActivity::class.java).apply {

                putExtra("type", type)

            }

            context!!.startActivity(intent)
        }

    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        binding = ActivityComputeBinding.inflate(layoutInflater)
        setContentView(binding?.root)
        type_a= intent.getStringExtra("type").toString()
        Log.e("onCreate: ", type_a)
        ImmersionBar.with(this)
            .transparentStatusBar()
            .init()
        initViews(type_a)
        initClick()
    }



     fun initViews(type: String) {
        initad()
        binding.ivBack.setOnClickListener { onBackPressed() }
         when(type){
             "1"->{
//                 binding.topBar.tvTitle.text ="最低工资"
             }
             "2"->{
                 binding.ivPhoto.setImageResource(R.drawable.ic_compute_bg2)
                 binding.tvTitle.text="职工养老保险缴纳计算"
                 binding.tvTitleAfter.text="职工养老保险缴纳计算"
//                 binding.topBar.tvTitle.text ="缴纳比例"
//                 binding.ivBg.setImageResource(R.drawable.ic_mk_bg2)
             }
             "3"->{
                 binding.ivPhoto.setImageResource(R.drawable.ic_compute_bg3)
                 binding.tvTitle.text="职工生育保险缴纳计算"
                 binding.tvTitleAfter.text="职工生育保险缴纳计算"
//                 binding.topBar.tvTitle.text ="药品目录"
//                 binding.ivBg.setImageResource(R.drawable.ic_mk_bg3)
//                 binding.tvFile.visibility=View.VISIBLE
//                 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
//                     initV()
//                 }
             }
             "4"->{
                 binding.tvTitle.text="职工失业保险缴纳计算"
                 binding.tvTitleAfter.text="职工失业保险缴纳计算"
                 binding.ivPhoto.setImageResource(R.drawable.ic_compute_bg4)
             }

         }

    }

    fun initClick(){

        binding.llComputeNow.thrillClickListener {
            if (binding.etSalary.text.toString().trim().isNullOrEmpty()||binding.etCom.text.toString().trim().isNullOrEmpty()||binding.etPerson.text.toString().trim().isNullOrEmpty()){
                Toast.makeText(this@ComputeInsuranceActivity,"请填写完整参数再计算", Toast.LENGTH_LONG).show()
            }else{
                computeAfter()
            }
        }

        binding.llBackNow.thrillClickListener {
          binding.etSalary.text.clear()
            binding.etPerson.text.clear()
            binding.etCom.text.clear()
            binding.llComputeBefore.visibility= View.VISIBLE
            binding.llComputeAfter.visibility= View.GONE
        }

        var mess="具体的缴费基数则根据个人的工资收入来确定。若工，资收入高于当地上一年度职工平均工资的300%，则以300%作为缴费基数，如果工资低于60%，则以60%作为缴费基数，工资在300%-60%之间的应据实申报。若工资收入无法确定则按照当地劳动行政部门公布的上一年度职工平均工资来确定缴费基数。"

        val dialog = AlertDialog.Builder(this@ComputeInsuranceActivity)
            .setTitle("提示")
            .setMessage(mess)
//            .setPositiveButton("前往授权") { _, _ ->
//                XXPermissions.startPermissionActivity(requireContext())
//            }
            .setNegativeButton("我知道了", null)
            .create()

        binding.llDetail.thrillClickListener {
            dialog.show()
        }

    }

    fun computeAfter(){
        binding.llComputeBefore.visibility= View.GONE
        binding.llComputeAfter.visibility= View.VISIBLE
        var total=binding.etSalary.text.toString().toDouble()
        var person=binding.etPerson.text.toString().toDouble()/100
        var com=binding.etCom.text.toString().toDouble()/100

        binding.tvPerson.text=(total*person).toInt().toString()
        binding.tvCom.text=(total*com).toInt().toString()
        var sal=binding.tvPerson.text.toString().toInt()+binding.tvCom.text.toString().toInt()
        binding.tvSalary.text=sal.toString()
    }




    fun   initad() {
//        myContext = requireContext()
//        lzyadsUtils=
//            com.lazyliuzy.commonui.utils.lzy.LZYADSUtils("Task1Activity", this@Task1Activity)
//        com.lazyliuzy.commonui.utils.lzy.LZYADSUtils.loadSimpleAd1(com.lazyliuzy.commonui.databinding.ActivityTask1Binding.flAd)
//        com.lazyliuzy.commonui.utils.lzy.LZYADSUtils.showAdCpTurn()

    }

}